import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src"),
      },
    ],
  },
  /* 打包配置 */
  base: "./",
  build: {
    brotliSize: false,
    emptyOutDir: false,
    outDir: "dist",
    chunkSizeWarningLimit: 1500, // 调整包的大小
    rollupOptions: {
      output: {
        //最小化拆分包
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
        entryFileNames: "assets/js/[name].[hash].js", // 用于命名代码拆分时创建的共享块的输出命名
        chunkFileNames: "assets/js/[name].[hash].js", // 用于输出静态资源的命名，[ext]表示文件扩展名
        assetFileNames: "assets/[ext]/[name].[hash].[ext]",
      },
    },
  },
  compilerOptions: {
    allowJs: true,
  },
  server: {
    port: "8090", // 指定启动端口
  },
});
